<?php 
	defined ('_JEXEC') or die ('Restricted access');
	jimport( 'joomla.application.component.controller' );
	jimport('joomla.filesystem.file');
	class HotrosControllerHotro extends HotrosController	{
	function __construct()	{
		parent::__construct();
		$this->registerTask( 'add'  , 	'edit' );
		$this->registerTask( 'publish', 'published' );
		$this->registerTask( 'unpublish', 'unpublished' );
		$this->registerTask('ordering', 'ordering');
		//$this->registerTask( 'orderup','orderup' );
		//$this->registerTask( 'orderdown','orderdown' );
		$this->registerTask( 'saveorder','saveorder' );
	}
	function orderup()		{
			$model = $this->getModel('hotro');
			$model->move(-1);
			$this->setRedirect( 'index.php?option=com_hotro');
		}
		function orderdown()		{
			$model = $this->getModel('hotro');
			$model->move(1);
			$this->setRedirect( 'index.php?option=com_hotro');
		}
		function saveorder()		{
			$cid 	= JRequest::getVar( 'cid', array(), 'post', 'array' );
			$order 	= JRequest::getVar( 'ordering', array(), 'post', 'array' );
			JArrayHelper::toInteger($cid);
			JArrayHelper::toInteger($order);
			$model = $this->getModel('hotro');
			$model->saveorder($cid, $order);
			$msg = JText::_( 'New ordering saved' );
			$this->setRedirect( 'index.php?option=com_hotro', $msg );
		}
	function published()	{
		$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
		JArrayHelper::toInteger($cid);
		if (count( $cid ) < 1) {
			JError::raiseError(500, JText::_( 'Bạn chưa chọn nickname' ) );
		}
		$model = $this->getModel('hotro');
		if(!$model->publish($cid, 1)) {
			echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
		}
		$this->setRedirect( 'index.php?option=com_hotro' );
	}
	function unpublished()	{
		$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
		JArrayHelper::toInteger($cid);
		if (count( $cid ) < 1) {
			JError::raiseError(500, JText::_( 'Bạn chưa chọn nickname' ) );
		}
		$model = $this->getModel(hotro);
		if(!$model->publish($cid, 0)) {
			echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
		}
		$this->setRedirect( 'index.php?option=com_hotro' );
	}
	function edit()	{
		JRequest::setVar( 'view', 'hotro' ); 
		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}
	function save()	{
		$model = $this->getModel('hotro');
		if ($model->store())  {
			$msg = JText::_( 'Nickname đã được lưu !' );
		} else {
			$msg = JText::_( 'Có lỗi ' );
		}
		$link = 'index.php?option=com_hotro';
		$this->setRedirect($link, $msg);
	}
	function remove()	{
		$model = $this->getModel('hotro');
		
		if(!$model->delete()) {
			$msg = JText::_( 'Có lỗi ! một vài nickname chưa xóa được ' );
		} else {
			$msg = JText::_( 'Nickname đã được xóa' );
		}
		$this->setRedirect( 'index.php?option=com_hotro', $msg );
	}
	function cancel()	{
		$msg = JText::_( 'Tác vụ bị hủy' );
		$this->setRedirect( 'index.php?option=com_hotro', $msg );
	}
}
?>